package edu.pku.sei.modeler.actions;

import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TreeViewer;

import edu.pku.sei.modeler.images.ImageProvider;

public class ReloadWorkSpaceAction extends Action {
	private TreeViewer tv;
	public ReloadWorkSpaceAction(TreeViewer tv) {
		this.tv = tv;
		this.setText("Reload workspace");
		this.setImageDescriptor(ImageProvider.getImageDescriptor(ImageProvider.MODEL_VIEW));
	}
	
	@Override
	public void run() {
		System.out.println("update tree view input");
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		try {
			root.refreshLocal(5, null);
//			if (this.viewer.getContentProvider() != MetaModelView.getMetaModelContentProvider()) {
//				ModelViewContentProvider provider = getMetaModelContentProvider();
//				provider.setTreeViewer(viewer);
//				this.viewer.setContentProvider(provider);
//			}
//			if (this.viewer.getLabelProvider() != MetaModelView.getMetaModelLabelProvider()) {
//				this.viewer.setLabelProvider(getMetaModelLabelProvider());
//			}
			
		} catch (CoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (root == null) {
			MessageDialog.openInformation(null, "debug_information",
					"workspace root is null!");
		} else {
			tv.setInput(root);
		}
	}
}
